package com.easy;

/**
 * Created by Lxk on 2019/6/8.
 */
public class Solution463 {

    public int islandPerimeter(int[][] grid) {
        if(grid==null || grid.length==0 || grid[0]==null || grid[0].length==0){
            return 0;
        }
        int col = grid[0].length;
        int row = grid.length;
        int maxX = 0;
        for(int i = 0;i < row; i++){
            int count = 0;
            for(int j = 0; j < col; j++){
                if(grid[i][j]==1){
                    count++;
                }
            }
            if(count>maxX){
                maxX = count;
            }
        }
        int maxY = 0;
        for(int i = 0;i < col; i++){
            int count = 0;
            for(int j = 0;j < row; j++){
                if(grid[j][i]==1){
                    count++;
                }
            }
            if(count>maxY){
                maxY = count;
            }
        }
        return (maxX + maxY)*2;
    }

}
